import httpUtil from "../utils/httpUtil"
import messageUtil from "../utils/messageUtil"
import logApi from "./logApi"
import paramApi from "./paramApi"
import userApi from "./userApi"
import zfbMiniPayApi from "./zfbMiniPayApi"

/**
 * 
 * @see https://console-docs.apipost.cn/preview/fc8d68b68a759bfb/82953b80ef7e371f?target_id=7652b84d-3fea-4f8c-8392-d678da8cf9b0
 */
const submitOrder = (mobile, proCode, province, yys, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		province,
		yys,
		p_code: '2024042604',
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrderf = (mobile, proCode, province, yys, p_code,successCallBack, errorCallBack) => {
	let params = {
		a:httpUtil.getA(),
		mobile,
		province,
		yys,
		p_code,
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrderfs = (mobile, proCode, province, yys, p_code,successCallBack, errorCallBack) => {
	let params = {
		a:'b85d8c2b041af3b11cd0f3445b0e50a6',
		mobile,
		province,
		yys,
		p_code,
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrderx = (mobile, proCode, province, yys, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		province,
		yys,
		p_code: '2024062402',
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrderp= (mobile, proCode, province, yys, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		province,
		yys,
		p_code: '2024070501',
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}else{
		params.param=''
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrders = (mobile, proCode, province, yys, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		province,
		yys,
		p_code: '2024061201',
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
const submitOrderms = (mobile, proCode, province, yys, successCallBack, errorCallBack) => {
	let params = {
		a: httpUtil.getA(),
		mobile,
		province,
		yys,
		p_code: '2024062401',
		type: 2, // 	1=365,2=30
		productType: 20,
		proType: 2, // 1-H5,2-支付宝小程序
		user_id: userApi.getUserId()
	}

	if (paramApi.getParam()) {
		params.param = paramApi.getParam()
	}
	if (proCode) {
		params.proCode = proCode
	}
	messageUtil.showLoading()
	logApi.addTuanyouChezhuQuanyiLog('请求前，参数：' + JSON.stringify(params))
	httpUtil.post('/api/rf/subOrder', params, res => {
		messageUtil.closeLoading()
		logApi.addTuanyouChezhuQuanyiLog('请求成功，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON.stringify(
			res))
		console.log('submitOrder：' + JSON.stringify(res))
		zfbMiniPayApi.zhouqiPayHandler(res.data.str, successCallBack, zhouqiError => {
			if (zhouqiError.errorMessage) {
				messageUtil.showFail(zhouqiError.errorMessage)
			}
			if (errorCallBack) {
				errorCallBack(zhouqiError)
			}
		})

	}, err => {
		logApi.addTuanyouChezhuQuanyiLog('请求发生错误，请求参数：' + JSON.stringify(params) + '，返回信息：' + JSON
			.stringify(
				err))
		if (errorCallBack) {
			errorCallBack(err)
		}
	})
}
export default {
	submitOrder,
	submitOrderf,
	submitOrders,
	submitOrderx,
	submitOrderms,
	submitOrderp,
	submitOrderfs
}